#include "Blocks/BasePumpkinBlock.h"

namespace PocketSurvival
{
    BasePumpkinBlock::BasePumpkinBlock(bool rotten) : isRotten(rotten)
    {
        addInheritance(this);
    }

    void BasePumpkinBlock::getCreativeValues(std::vector<int32_t> &blockVec)
    {
        blockVec.push_back(Terrain::MakeBlockValue(getIndex(), 0, SetSize(SetIsDead(0, true), 1)));
        blockVec.push_back(Terrain::MakeBlockValue(getIndex(), 0, SetSize(SetIsDead(0, true), 3)));
        blockVec.push_back(Terrain::MakeBlockValue(getIndex(), 0, SetSize(SetIsDead(0, true), 5)));
        blockVec.push_back(Terrain::MakeBlockValue(getIndex(), 0, SetSize(SetIsDead(0, true), 7)));
    }

    void BasePumpkinBlock::getDropValues(int32_t oldValue, int32_t newValue, int32_t toolLevel, std::vector<BlockDropValue> &dropValues)
    {
        int32_t size = GetSize(Terrain::ExtractData(oldValue));
        if (size >= 1)
        {
            int32_t value = setDamage(Terrain::MakeBlockValue(getIndex(), 0, SetSize(SetIsDead(0, true), size)), getDamage(oldValue));
            dropValues.push_back(BlockDropValue{value, 1});
        }
    }

    const std::vector<BoundingBox> &BasePumpkinBlock::getCustomCollisionBoxes(int32_t value)
    {
        int32_t size = GetSize(Terrain::ExtractData(value));
        return BlockConstans::pumpkinCollisionBoxes[size];
    }

    float BasePumpkinBlock::getNutritionalValue(int32_t value)
    {
        if (GetSize(Terrain::ExtractData(value)) != 7)
        {
            return 0.0f;
        }
        return Block::getNutritionalValue(value);
    }
    int32_t BasePumpkinBlock::getDamage(int32_t value)
    {
        return (Terrain::ExtractData(value) & 0x10) >> 4;
    }
    int32_t BasePumpkinBlock::setDamage(int32_t value, int32_t damage)
    {
        int32_t num = Terrain::ExtractData(value);
        return Terrain::ReplaceData(value, (num & -17) | ((damage & 1) << 4));
    }
    int32_t BasePumpkinBlock::getDamageDestructionValue(int32_t value)
    {
        if (isRotten)
        {
            return 0;
        }
        int32_t data = Terrain::ExtractData(value);
        return setDamage(Terrain::MakeBlockValue(244, 0, data), 0);
    }
    int32_t BasePumpkinBlock::getRotPeriod(int32_t value)
    {
        if (GetIsDead(Terrain::ExtractData(value)) == false)
        {
            return 0;
        }
        return DefaultRotPeriod;
    }

} // namespace PocketSurvival
